**********************************************
*GRAPHS: Teele Final Manuscript Replication File
*Compiled December 2017
***********************************************

cd "~/Dropbox/Book/Teele_PUP/images_final/images_replication"

version 14.1

graph set eps fontface Avenir
graph set window fontface Avenir

*********************
*Fig 1.1: Listogram 
*********************

import excel "Teele_book_replication.xlsx", sheet("Full_Franchise") firstrow clear

sort Full_Franchise /*The date of major extension of women's vote*/ 
count /*Data for 172 countries */
bysort suffragedecade : g N=_n /*ranks extensions within decade*/ 

*standard listogram
# delimit ; 
twoway (scatter N suffragedecade, mlabel(ccode) mcolor(black) mlabcolor(gs5) mlabsize(*.9) mlabgap(*3) mfcolor(black)  msym(none)), xtitle("") ytitle("Number of Countries")  xlabel(1880(20)2010) xtick(1890(20)2010)  legend(off) scheme(tufte) ;

graph export "fig1.eps", replace;
graph export "fig1.pdf", replace;
# delimit cr

**Path Info **
/* 
1 = country granted universal franchise to men and women at the same time, the first time suffrage was extended. 

2 = country had suffrage imposed by a metropole or occupying power. 

3 = country extended suffrage to women gradually, after some men already had voting rights. 

4 = country had a mixed path (i.e. might have had some male voters early on, then a new constitution after regime change or something like that gave universal suffrage).  
*/ 


**********************************************
*Fig 2.1: Sectoral Break Down 
**********************************************

*****
*Fig 2.1 A 
*****
import excel "Teele_book_replication.xlsx", sheet("Global") firstrow clear

count if suffragedecade==decade & nonag!=. /*65 countries have this data */ 

# delimit ; 
twoway scatter nonag my_date if suffragedecade==decade , mlabel(ccode) msym(none) mlabsize(*.9)
|| lfit nonag my_date if suffragedecade==decade ,
xtitle("Year of Suffrage") ytitle("Non-Agricultural Workforce (%)") legend(off)  xscale(titlegap(*10)) scheme(tufte) name(g1nonag, replace);

graph export "fig2-a.eps", replace;
graph export "fig2-a.pdf", replace;
# delimit cr

*keep suffragedecade my_date nonag decade ccode


*****
*Figure 2.1 B
*****
import excel "Teele_book_replication.xlsx", sheet("Global") firstrow clear

drop if ccode=="AUT" 

keep if tminus>=-20 & tminus<=20

gen haszero=1 if tminus==0 & nonag!=.
egen tokeep=max(haszero), by(ccode) 
keep if tokeep==1 /*64 countries with data at tminus zero */

*how many countries are in each dataset? 
gen post45=0 if Listogram<1945
replace post45=1 if Listogram>=1945
count if tminus==0 & nonag!=. & post45==0 /* 14*/ 
count if tminus==0 & nonag!=. & post45==1/* 50*/


separate nonag, by(post45)
collapse nonag*, by(tminus)

twoway (line nonag? tminus) (line nonag tminus, lcolor(blue)) , xline(0, lcolor(red)) scheme(tufte) xtitle("Years from Suffrage") ytitle("Non-Agricultural Workforce (%)") text(59 -10 "Pre-1945 enfranchisers") text(52 -15 "All", color(blue)) text(47 -10 "Post-1945 enfranchisers") legend(off) xscale(titlegap(*10)) 

graph export "fig2-b.eps", replace
graph export "fig2-b.pdf", replace


**********************************************
*Fig 2.2: Women's Economic Activity 
**********************************************

****
*2.2 A
****

import excel "Teele_book_replication.xlsx", sheet("Global") firstrow clear

*Data from AUT looks wonky
keep if year <=1990
count if suffragedecade==decade & percentwomen!=.
*32 countries have observation of percentwomen in labor force in the year of suffrage. Perhaps I can ipolate? 

# delimit ; 
twoway scatter percentwomen my_date if suffragedecade==decade  & ccode!="AUT" , mlabel(ccode) msym(none) 
|| lfit percentwomen my_date if suffragedecade==decade & ccode!="AUT",
xtitle("Year of Suffrage") ytitle("Economically Active Women (%)") legend(off) scheme(tufte) xscale(titlegap(*10)) 
;

graph export "fig3-a.eps", replace
graph export "fig3-a.pdf", replace

****
*2.2 B
****

import excel "Teele_book_replication.xlsx", sheet("Global") firstrow clear

*Data from AUT looks wonky
drop if ccode=="AUT" 

keep if tminus>=-20 & tminus<=20

gen haszero=1 if tminus==0 & nonag!=.
egen tokeep=max(haszero), by(ccode) 
keep if tokeep==1 /*64 countries with data at tminus zero */

*how many countries are in each dataset? 
gen post45=0 if Listogram<1945
replace post45=1 if Listogram>=1945
count if tminus==0 & percentwomen!=. & post45==0 /*14 */ 
count if tminus==0 & percentwomen!=. & post45==1/* 17 --Total 31*/


separate percentwomen, by(post45)
collapse percentwomen*, by(tminus)

twoway (line percentwomen? tminus) (line percentwomen tminus, lcolor(blue)) , xline(0, lcolor(red)) scheme(tufte) xtitle("Years from Suffrage") ytitle("Economically Active Women (%) ") text(26 14 "Pre-1945 Enfranchisers, n=14") text(22.5 14 "All, n=31", color(blue)) text(19.5 14 "Post-1945 Enfranchisers, n=17") legend(off) ylabel(15(5)35) xscale(titlegap(*10)) 

graph export "fig3-b.eps", replace
graph export "fig3-b.pdf", replace



********************************
*Figure 2.3 Warfare in YEAR of suffrage (and surrounding analysis)
********************************

import excel "Teele_book_replication.xlsx", sheet("COW_modified") firstrow clear

*How many countries were at war? 
preserve 

keep if year==Full_Franchise
tab iswars
tab civwars
tab eswars
list Country if iswars!=0
list Country if civwars!=0
list Country if eswars!=0
*For 90 countries for which data is available, 13 countries were involved in an inter-state war in the year that suffrage was extended (14.5%), 8 were involved in a civil war in that year (9%) and one was involved in an extra-state war. A few overlaps...overall, 20/90 cases had some war going on when they extended the vote. 
restore 


*Warfare in 10 YEARS prior to suffrage

keep if past10==1
recode iswars civwars eswars (0=.) (2=1) /*Simplify war coding)*/ 
egen anywar=rowmax(iswars civwars eswars)
  

*by countrycode, find the max of anywar etc 

collapse (max) anywar iswars civwars eswars (firstnm) suffragedecade Full_Franchise, by(ccode) 
gen n=1
gen nowar=1 if anywar==.


* countries involved in anywar during decade before suffrage
preserve
collapse (count) n anywar 
list 
restore
di 34/90 /* 37.7 percent of countries were involved in SOME form of war in the decade just prior to suffrage */ 

*********
*Graph of Figure 2.3
**********

collapse (count) n anywar iswars civwars eswars nowar  , by(suffragedecade)


**Any war in years before suffrage** 

gen w="w"

# delimit ;
twoway (connected nowar suffragedecade, msize(tiny) mlab(nowar) msym(none) mlabpos(12) lpattern(dash) lwidth(medthick))  

(connected anywar suffragedecade, lcolor(red) msym(Dh)  mlabel(anywar) msize(tiny) mlabpos(6) msym(none) ), 

legend(label(1 "No war past 10 years") label(2 "At war past 10 years") ring(0) pos(2) col(1) ) 

xtitle("Decade of Suffrage") ytitle("# Countries Extended Suffrage in Decade") xscale(titlegap(*10)) scheme(tufte) ;

graph export "fig4.eps", replace
graph export "fig4.pdf", replace



*******************************************
*Figure 2.4: Sex Ratio
******************************************


 import excel "Teele_book_replication.xlsx", sheet("Global") firstrow clear

keep if suffragedecade<=1990

keep if suffragedecade==decade /*97 countries left*/ 

sort suffragedecade my_date
tostring my_date, replace
egen clock5=ends(my_date), tail 

bys suffragedecade: gen clock3=_n 

gen clock=.
replace clock=7 if clock3==1
replace clock=1 if clock3==2
replace clock=4 if clock3==3
replace clock=10 if clock3==4
replace clock=5 if clock3==5
replace clock=6 if clock3==6
replace clock=2 if clock3==7
replace clock=12 if clock==.
replace clock= 12 if ccode=="DNK" 
replace clock=4 if ccode=="ISL" 
replace clock=3 if ccode=="ARG" 
replace clock=4 if ccode=="GTM" 
replace clock=9 if ccode=="MEX"
replace clock=3 if ccode=="NIC"
replace clock=9 if ccode=="JAM"
replace clock=6 if ccode=="HTI"
replace clock=9 if ccode=="BEL" 

gen sex100=sexratio*100

destring my_date, replace
# delimit ; 
twoway scatter sex100 my_date if suffragedecade==decade , mlabel(ccode) mlabvpos(clock) msym(none) msize(tiny)
|| lfit sex100 my_date if suffragedecade==decade ,
xtitle("Year of Suffrage") ytitle("Men per 100 Women") xscale(titlegap(*10)) legend(off) scheme(tufte) ysca(r(85(10)115)) yla(85(10)115) xla(1900(10)1980)
;


graph export "fig5.eps", replace
graph export "fig5.pdf", replace



******************************************************************************
*United Kingdom
******************************************************************************

*******************************************
*Figure 3.1: HOC Party wins 
******************************************
import excel "Teele_book_replication.xlsx", sheet("HOC_Parties") firstrow clear


# delimit ; 
twoway (connected  cons_s year, lcolor(gs2) mlabpos(0) msym(none) msize (small) lcolor(gs9) mcolor(gs9) lpattern(dash) lwidth(medthick))

(connected lib_s year, lcolor(gs3)  mlabpos(0) msym(none) msize (small) lcolor(gs4) mcolor(gs4) lpattern(dot)lwidth(medthick))

(connected lab_s year, lcolor(gs12)  mlabpos(0) msym(none) msize (small)  mcolor(gs2) lwidth(medthick)) 

(connected other_s year, lcolor(gs4)  mlabpos(0) msym(none) msize (small) lcolor(gs5) mcolor(gs5) lpattern(dash_dot) lwidth(medthick)) , 

xla(1900(5)1930)
xline(1917,lcolor(red)) xline(1928,lcolor(red)) yscale(titlegap(*10))
ytitle("Percent of Seats") xtitle("") 

legend(off)

text(62 1906 "Lib", place(s))
text(55 1922 "Cons", place(s))

text(10 1910 "Lab", place(s))
text(17 1901 "Other", place(s))
text(44 1929 "Lab", place(n))
		
text(67 1900 "(C)", place(s) size(vsmall))
text(67 1906 "(Lib)", place(s) size(vsmall))
text(67 1910 "(Lib-Nat)", place(sw) size(vsmall))
text(67 1910.9  "(Lib-Nat)", place(s) size(vsmall))
text(67 1918.9 "(C-Coal)", place(s) size(vsmall))
text(67 1922 "(C)", place(s) size(vsmall))
text(67 1923 "(C)", place(s) size(vsmall))
text(67 1924 "(C)", place(s) size(vsmall))
text(67 1929 "(Lab)", place(s) size(vsmall))
text(-2 1917 "4th Reform", place(s) size(tiny))
text(-2 1928 "5th Reform", place(s) size(tiny))



scheme(tufte)
 ; 
# delimit cr

graph export "fig7.eps", replace
graph export "fig7.pdf", replace



******************************************************************************
*United States of America
******************************************************************************
*************
*Figure 4.1: US Timeline
*************

 import excel "Teele_book_replication.xlsx", sheet("US_raw") firstrow clear

 order region1 state* fr_school fr_municipal fr_presidential fr_full
 replace fr_full=. if fr_full==1920
 g end=1920
 drop if inlist(scode,"AK","HI")
 encode state, gen(state1)
replace fr_school = 1870 if fr_school<=1870 & fr_school!=.
replace statehood_year=. if statehood_year <1870

gen A="A" if nineteenth_year!=.

# delimit ;  
twoway
rspike fr_school end state1, horiz ysc(reverse) lpattern(dot) ||
rspike fr_municipal end state1, horiz ysc(reverse) lpattern(dash) ||
rspike fr_presidential end state1, horiz ysc(reverse) lpattern(solid) ||
rspike fr_full end state1, horiz ysc(reverse) xlabel(, labsize(small) ) lpattern(solid) lwidth(medthick) ysc(reverse alt) msize(tiny) mlabpos(3) ||
scatter state1 nineteenth_year, mlabel(A) msymbol(none) mlabsize(tiny) ysc(reverse) ||
scatter state1 statehood_year, msymbol("+") msize(small) ysc(reverse) 
ylabel(1/48, ang(h) labsize(vsmall) noticks nogrid valuelabel) ytitle("") legend( ring(0) position(7) col(1) label(1 "School") label(2 "Municipal") label(3 "Presidential") label(4 "Full") label(5 "Ratified 19th") label(6 "Statehood") size(vsmall) order(6 1 2 3 4 5)) scheme(tufte) xscale(range(1870 1922)) xlab(1870 (10) 1920) 
 ;
# delimit cr


graph export "fig9.eps", replace
graph export "fig9.pdf", replace
 
 
*************
*Figure 4.2: Maps 
*************

*email teele.academic@gmail.com for the mapping files
 
*************
*Figure 4.3 a: NAWSA Membership
*************

import excel "Teele_book_replication.xlsx", sheet("US_Panel") firstrow clear

encode region, gen(region1)
collapse (mean) nawsa_membpc, by(region1 year)
sort year
*region1: 1 midwest, 2 NE, 3 S, 4 W

#delimit ; 

twoway 
(connected nawsa_membpc year if region1==1, msize(small)  mlabpos(0.3) msym(none) lcolor(gs9) mcolor(gs9) lwidth(medthick) lpattern(dash) ) 
(connected nawsa_membpc year if region1==2, msize(small) mlabpos(0.3) msym(none) lcolor(gs4) mcolor(gs4) lwidth(thick) lpattern(dot)) 
(connected nawsa_membpc year if region1==3, msize(small) mlabpos(0.3) msym(none) lcolor(gs2) lwidth(medthick) mcolor(gs2)) 
(connected nawsa_membpc year if region1==4, msize(small)  mlabpos(0.3) msym(none)lcolor(gs5) mcolor(gs5) lwidth(medthick) lpattern(dash_dot)) if year>=1890 , 

legend( ring(0) position(11) col(1) label(1 "Midwest") label(2 "Northeast") label(3 "South") label(4 "West") order(4 2 1 3) ) 
ytitle("NAWSA Members per Thousand Pop.") scheme(tufte) xtitle("") 
text(1.9 1897 "W", place(s) size(small))
text(5.35 1914 "W", place(s) size(small))
text(0.6 1905 "NE", place(s) size(small))
text(1.5 1914 "NE", place(n) size(small)) 
text(-.08 1897 "S", place(n) size(small))
text(.9 1920 "S", place(nw) size(small))
text(.099 1893 "MW", place(w) size(small))
text(.7 1914 "MW", place(n) size(small)) 

yscale(titlegap(*10))
 ; 

		
# delimit cr

graph export "fig11-a.eps", replace
graph export "fig11-a.pdf", replace

*************
*Figure 4.3 b: WCTU Dues per capita
*************

 
import excel "Teele_book_replication.xlsx", sheet("US_Panel") firstrow clear

la var wctu_dues "WCTU Dues"

encode region, gen(region1)
collapse (mean) wctu_dues, by(region1 year)
sort year

*region1: 1 midwest, 2 NE, 3 S, 4 W


#delimit ; 

twoway 



(connected wctu_dues year if region1==1, msize(small)  mlabpos(0.3) msym(none) lcolor(gs9) mcolor(gs9) lwidth(medthick)lpattern(dash)) 

(connected wctu_dues year if region1==2, msize(small) mlabpos(0.3) msym(none)  lcolor(gs4) mcolor(gs4) lwidth(thick) lpattern(dot)) 

(connected wctu_dues year if region1==3, msize(small) mlabpos(0.3) lwidth(medthick) msym(none) lcolor(gs2) mcolor(gs2)) 

(connected wctu_dues year if region1==4, msize(small)  mlabpos(0.3) msym(none) lcolor(gs5) mcolor(gs5) lwidth(medthick)lpattern(dash_dot)) if year>=1890

, 

legend( ring(0) position(11) col(1)  label(1 "Midwest")  label(2 "Northeast") label(3 "South")label(4 "West") order(2 1  4 3) ) 
ytitle("WCTU Dues per Capita") scheme(tufte) xtitle("") yscale(titlegap(*10))

text(475 1893 "W", place(s) size(small))
text(750 1891 "NE", place(n) size(small))
text(1402 1905 "MW", place(s) size(small))
text(150 1918 "S", place(s) size(small)) name(n2, replace)
 ; 

		
# delimit cr

graph export "fig11-b.eps", replace
graph export "fig11-b.pdf", replace



*************
*Figure 4.4: Bill Types 
*************

 import excel "Teele_book_replication.xlsx", sheet("bill_types") firstrow clear

 
collapse (sum) elected taxpayer property aliens race prohibition school municipal presidential primary literacy full, by (part_full prev_decade)


drop if prev>1920

gen full_suffrage=1 if part_full=="Full" 
replace full_suffrage=0 if part_full=="Limited" 

# delimit ; 
twoway 
(connected full prev_decade if full_suffrage==1, lcolor(gs1)  mlabpos(12) msym(none) msize(small)  mcolor(gs16) lpattern(solid)  lwidth(medthick))

(scatter full prev_decade if full_suffrage==1, lcolor(none) mlab(nfull) mlabpos(3) msym(none) msize(small)  mcolor(none) )

(connected municipal prev_decade if full_suffrage==0, lcolor(gs5) mlabpos(0) msym(none) msize (small) mcolor(gs3) lpattern(dash) lwidth(medthick))

(connected school  prev_decade if full_suffrage==0, lcolor(gs2) mlabpos(0) msym(none) msize (small) mcolor(gs2) lpattern(dot) lwidth(thick))

(connected presidential prev_decade if full_suffrage==0, lcolor(gs12) mlabpos(0) msym(none) msize(small)  mcolor(gs12) lpattern(solid) lwidth(medthick) ) ,

xscale(range(1840 1920)) xlab(1840 (10) 1920)

 scheme(tufte) ytitle("Total Bills Proposed per Decade") xtitle("")
 legend(label(1 "Full") label(3 "Municipal") label(4 "School")  label(5 "Presidential") order(1 3 4 5)    
 col(1) ring(0) pos(11))
 
 text(121 1899 "F", place(n))
 text(60 1899 "M", place(n))
 text(42 1899 "S", place(s))
  text(-.9 1899 "P", place(n))
 
 ;
 
# delimit cr

graph export "fig12.eps", replace
graph export "fig12.pdf", replace


*************
*Figure 4.5: Competition over time 
*************

 import excel "Teele_book_replication.xlsx", sheet("US_Panel") firstrow clear
keep if year>=1870 & year<1920

collapse (mean) comp_majsurplus machine_peo comp_runnertowinner, by(region decade) 

encode region, gen(region1) 

gen w = "w" 
gen ne = "n"
gen mw = "m"
gen s = "s"

la var comp_majsurplus "Majority Surplus"
la var machine_peo "Frac. Pop. Machine" 
la var comp_runnertowinner "Runner-up to Winner" 
sort decade 

foreach var in comp_majsurplus machine_peo comp_runnertowinner   {

local i=`i'+1

local lbvar : variable label `var' 

#delimit ; 
twoway 
(connected `var' decade if region1==1, mlabsize(large) mlab(mw) mlabpos(0) 
msym(none) lcolor(gs9) mcolor(gs9) lpattern(dash) ) 

(connected `var' decade if region1==2, mlabsize(large) msize(vhuge) mlab(ne) mlabpos(0) msym(none)  lcolor(gs4) mcolor(gs4) lpattern(dot) lwidth(medthick) ) 

(connected `var' decade if region1==3, mlabsize(large) msize(vhuge) mlab(s) mlabpos(0) msym(none) lcolor(gs2) mcolor(gs2) lwidth(medthick) ) 

(connected `var' decade if region1==4, mlabsize(large) msize(vhuge) mlab(w) mlabpos(12) msym(none) lcolor(gs5) mcolor(gs5) lpattern(dash_dot) lwidth(medthick)  ) , 

legend( ring(0) position(11) col(1) label(1 "Midwest") label(2 "Northeast") label(3 "South") label(4 "West") order(4 2 1 3 ) )
ytitle("mean") xtitle("") xlabel( 1865 "1870s" 1875 "1880s" 1885 "1890s"  1895 "1900s" 1905 "1910s" 1915 "1920s", tlwidth(vhuge) labsize(large)) name(`var', replace)  legend(off) ylabel(, labsize(large)) scheme(tufte) yscale(titlegap(*10)) ytitle("Mean"); 
# delimit cr

graph export "fig13-`i'.eps", replace
graph export "fig13-`i'.pdf", replace

} 

 
 
*********************
*Fig 4.6: Before and After Suffrage 
*********************
import excel "Teele_book_replication.xlsx", sheet("US_session") firstrow clear
keep if yearmin>=1870 & yearmax<1921

egen scode1 = group(scode)

tsset scode1 yearmin

sort scode yearmin

by scode: gen reforms = sum(passed_both)


*Want the time periods to be legislative sessions. 

by scode: gen suff_session = session if reforms == 1 & reforms[_n-1] == 0
by scode: egen t = max(suff_session)
replace t=session - t 

collapse (mean) comp*  nawsa_membpc  machine_n ///
         , by(t)



twoway line nawsa_membpc t if t>=-3 & t<=3, xline(0, lcolor(red)) scheme(tufte) xtitle("Legislative Sessions Before and After Suffrage Passes Legislature") ytitle("NAWSA Membership Per Capita") xscale(titlegap(*10)) 

graph export "fig14-1.eps", replace
graph export "fig14-1.pdf", replace

	 
twoway line comp_majsurplus t if t>=-5 & t<=3, xline(0, lcolor(red)) scheme(tufte) xtitle("Legislative Sessions Before and After Suffrage Passes Legislature") xscale(titlegap(*10)) ytitle("Majority Surplus") 

graph export "fig14-2.eps", replace
graph export "fig14-2.pdf", replace

twoway line comp_runner t if t>=-3 & t<=3, xline(0, lcolor(red)) scheme(tufte) xtitle("Legislative Sessions Before and After Suffrage Passes Legislature") ytitle("Runner-up/Winner") xscale(titlegap(*10))

graph export "fig14-3.eps", replace
graph export "fig14-3.pdf", replace



********************
*Fig 4.7 Raw Interaction Graphs
********************
import excel "Teele_book_replication.xlsx", sheet("US_session") firstrow clear



*Terciles of mobilization 
sum nawsa_membpc, detail
_pctile nawsa_membpc,  p(33 66 99)
return list 
gen NLMH=. 
replace NLMH = 0 if nawsa_membpc<=`r(r1)' 
replace NLMH = 1 if  nawsa_membpc>`r(r1)' & nawsa_membpc<=`r(r2)' 
replace NLMH = 2 if  nawsa_membpc>`r(r2)' & nawsa_membpc<=`r(r3)' 
label define NLMH 0 "Mobilization Low" 1 "Mobilization Medium" 2 "Mobilization High"
label values NLMH NLMH

 *

foreach var in  comp_runnertowinner comp_majsurplus { 
	 local i=`i'+1
		local lb_var : variable label `var'
		ren `var' d
		ren nawsa_membpc x
		ren passed_both y

		sum d, detail
		_pctile d, p(10(10)99)
		*gen competition bins
		egen bins=cut(d), at(`r(r1)' `r(r2)' `r(r3)' `r(r4)' `r(r5)' `r(r6)' `r(r7)' `r(r8)' `r(r9)')
		egen bin_it_up = mean(y), by(NLMH bins )
		
	
		label define title 0 "Suffrage Support" 1 "" 2 ""
		
				
	forval n=0/2 {
			egen nobs_`n'=count(bins) if NLMH==`n', by(bins)
			local f`n': label NLMH `n'
			count if NLMH== `n'
			local N=`r(N)'
			sum d if NLMH== `n'
			local avX =round(`r(mean)',.01)
			sum y if NLMH==`n'
			local avY=round(`r(mean)',.01)
			
			local t`n': label title `n'
			
			sum d
			local rm=`r(min)'
			local rma=`r(max)'
			
			
			gen wsize=nobs_`n'/bins

			
			# delimit  ;
			twoway 	(scatter bin_it_up bins if NLMH == `n' [w=nobs_`n'],  msize(small)  msym(oh)  mcolor(sand))
					(lowess y d if NLMH == `n' ,  lcolor(green) lpattern(line) lwidth(thick) ) 
					(lfit y d  if NLMH == `n', lcolor(gs4) lwidth(thick)) , 
					legend(off) xtitle("") yscale(range(0 .5)) xscale(range(`rm' `rma')) ylab(0(.10).5) ytitle("`t`n''", size(vhuge))  subtitle("`f`n'', n=`N'", size(huge)) name(g`n', replace) scheme(tufte)   text( `avY' `avX' "+", color(red)) ;
					
graph export "fig15-`i'_`n'.eps", replace ;
graph export "fig15-`i'_`n'.pdf", replace ;
			
			# delimit cr
			drop wsize

				}  
				
				

ren d `var' 
ren x nawsa_membpc 
ren y passed_both 
drop bin*
drop nobs*
	label drop title
 
}



****Machine Variable

import excel "Teele_book_replication.xlsx", sheet("US_session") firstrow clear

sum nawsa_membpc, detail
_pctile nawsa_membpc,  p(33 66 99)
return list 
gen NLMH=. 
replace NLMH = 0 if nawsa_membpc<=`r(r1)' 
replace NLMH = 1 if  nawsa_membpc>`r(r1)' & nawsa_membpc<=`r(r2)' 
replace NLMH = 2 if  nawsa_membpc>`r(r2)' & nawsa_membpc<=`r(r3)' 
label define NLMH 0 "Mobilization Low" 1 "Mobilization Medium" 2 "Mobilization High"
label values NLMH NLMH


foreach var in  machine_percent  { 
		local lb_var : variable label `var'
		ren `var' d
		ren nawsa_membpc x
		ren passed_both y

		sum d, detail
		_pctile d , p(51(10)99)  /*all other variables */ 
		*_pctile d , p(60(10)99)   /*if `var'==comp_thirdfrac */ 
		return list
		*gen competition bins
		egen bins=cut(d), at(`r(r1)' `r(r2)' `r(r3)' `r(r4)' `r(r5)' `r(r6)')
		egen bin_it_up = mean(y), by(bins NLMH)
		
		label define title 0 "Suffrage Support" 1 "" 2 ""
				
	forval n=0/2 {
			egen nobs_`n'=count(bins) if NLMH==`n', by(bins)
			local f`n': label NLMH `n'
			count if NLMH== `n'
			local N=`r(N)'
			sum d if NLMH== `n'
			local obs=`N'
			local avX =round(`r(mean)',.01)
			sum y if NLMH==`n'
			local avY=round(`r(mean)',.01)
			local t`n': label title `n'
			
			# delimit  
			twoway 	(scatter bin_it_up bins if NLMH == `n' [w=nobs_`n'],  msize(small)  msym(oh)  mcolor(sand))
					(lowess y d if NLMH == `n' ,  lcolor(green) lpattern(line) lwidth(thick) ) 
					(lfit y d  if NLMH == `n', lcolor(gs12) lwidth(thick) ) , 
					legend(off) xtitle("") yscale(range(.0 .5)) xsca(range(0(.34) 1)) ylab(0(.10).5) ytitle("`t`n''", size(vhuge))  subtitle("`f`n'', n=`obs'", size(huge)) name(g`n', replace) scheme(tufte)  text( `avY' `avX' "+", color(red)) ;
			
			graph export "fig15-3_`n'.eps", replace ;
graph export "fig15-3_`n'.pdf", replace ;
			# delimit cr
				} 			

ren d `var' 
ren x nawsa_membpc 
ren y passed_both 
drop bin*
drop nobs*
label drop title

}


 
*********************
*Fig 4.8: Prohibition 
*********************


import excel "Teele_book_replication.xlsx", sheet("Drycounties") firstrow clear
 encode scode, gen(scode2)

forval x=1/15 {
local statename: label scode2 `x'
qui sum fr_full if scode2==`x'
twoway line fract year if scode2==`x' & year<1920, lwidth(medthick) xline(`r(mean)', lpattern(dash)) title("`statename'") name(g`x', replace) ytitle("") xtitle("")  nodraw
}

forval x=1/15 {
local graphnames `graphnames' g`x'
}
graph combine `graphnames', l1("Fraction of Counties under Prohibition") ycommon 

 graph export "fig16.eps", replace
graph export "fig16.pdf", replace

******************************************************************************
*FRANCE
******************************************************************************


************************
*5.1 Partisan composition of Chamber of deputies
************************

import excel "Teele_book_replication.xlsx", sheet("Fr_parties_Graham") firstrow clear
* Composition of Chamber of Deputies since, 1870

*the following graph ignores party 1 because only one obs. 


# delimit ;
twoway line
p_party4 p_party8 p_party9 p_party10 p_party7 
p_party2 p_party6 p_party5 p_party3 start, 
text(.51 1872 "Right")
text(.48 1881 "Radical")
text(.46 1924 "Center-Right")
text(.15 1919 "Socialist")
text(.1 1930 "Communist")
text(.12 1873 "Other")
text(.11 1898 "Center")
text(.01 1871 "Ind.")
text(.05 1902 "None")
legend(off) scheme(tufte)
ytitle("Share of Seats in Lower House") xtitle("Election Year")
xlabel(1871 1876 1877 1881(4)1893 1898(4)1914 1919 1924(4) 1936, alt labsize(small)) xscale(titlegap(*10))

;



graph export "fig17.eps", replace
graph export "fig17.pdf", replace


**********************
**5.2 Roll Call vote
***********************
import excel "Teele_book_replication.xlsx", sheet("Fr_rollcall") firstrow clear


# delimit ; 
graph hbar (sum) V_3 V_2 V_1, 
stack over(Party, sort(order) )
legend(label(1 "Yay") label(2 "Nay") label(3 "Abstain") row(1) ring(0) pos(6) order(1 - 2 - 3) textw(.5))
blabel(bar, j(center) position(inside) format(%9.0f) color(white)) name(g1, replace) bar(1, color(gs6)) bar(3, color(gs12))scheme(tufte)
 ; 

# delimit cr

*NOTE: I had to hand-edit some of the positions of the numbers inside. 
graph export "fig18.eps", replace
graph export "fig18.pdf", replace

**********************
**5.3 Map of Clerical Peril
***********************

*email teele.academic@gmail.com for map files. 

**********************
**5.5 Votes by party and the clerical peril
***********************

import excel "Teele_book_replication.xlsx", sheet("Fr_rollcall") firstrow clear

la var oath "\% Oath Takers, 1791" 
la var left "Left Parties"
la var center "Radical Center" 
la var right "Right Parties" 

*create decile bins of the clerical peril
egen bins = cut(clerical_peril), at(0(10)100)

*create a dummy variable of the 1919 vote. 
gen vote01=0 if VOTE=="0"
replace vote01=1 if VOTE=="1"
*average vote share by decile bins and whether the parties are the radical centrists or not
egen bin_it_up = mean(vote01), by(bins center)
*find the number of observations in each group
egen nobs_notcenter=count(bins) if center!=1, by(bins)
gen size_notcenter=nobs_notcenter/248

egen nobs_center=count(bins) if center==1, by(bins)

egen nobs=count(bins), by(bins)
gen size=nobs/544

#delimit;
twoway (scatter bin_it_up bins if center == 1,  mlabpos(12) mlab(nobs_center) msym(oh))
(lpoly vote01 clerical_peril if center == 1, lwidth(thick) ) 
(scatter bin_it_up bins if center == 0, mcolor(gray) mlab(nobs_notcenter) mlabcolor(gray) msym(oh))
(lpoly vote01 clerical_peril if center == 0, lcolor(gray) lwidth(thick) ), 
legend(off) 
text(.90 90 "Left and Right", color(gray)) 
text(.40 90 "Radicals")
xtitle("Clerical Peril deciles, 1791", size(large)) 
yscale(range(.0 1)) xlab(,labsize(large) ) xsca(titlegap(*10)) 

ylab(0(.20)1,labsize(large)) ytitle("Share of Deputies For Suffrage, 1919", size(large)) scheme(tufte);

graph export "fig21.eps", replace
graph export "fig21.pdf", replace

********************
*5.4 Radicals and Religiosity
********************

import excel "Teele_book_replication.xlsx", sheet("Fr_rollcall") firstrow clear
collapse (sum) left center right (mean) clerical_peril (firstnm) department dept_1914, by(dcode)
egen totaldep=rowtotal(left center right)
gen center_percent=center/totaldep

la var clerical_peril "Clerical Peril, 1791"
graph twoway (scatter center_percent clerical_peril, msym(none) mlabel(dept_1914) ) (lfit center_percent clerical_peril ), name(g1, replace) legend(off) ytitle("Radical MPs in Department (%)")  xsca(titlegap(*10)) scheme(tufte) 

graph export "fig20.eps", replace
graph export "fig20.pdf", replace





**********
*5.6 Interaction Plots
**********

cd "~/Dropbox/Book/ms/images/France"
use "France_book.dta", clear


*Party Group Dummy 

gen LCR=. 
replace LCR = 0 if left==1 
replace LCR = 1 if  center==1
replace LCR = 2 if  right==1
label define LCR  0 "Left" 1 "Center" 2 "Right"
label values LCR LCR

 label define comp_LMH 0 "Low Competition" 1 "Medium Competition" 2 "High Competition" 

	
	
*Make a graph for low competition by party clerical peril and support

*sectour==went to second ballot. binary
*cm_1914 == any dual mandate
*incumbent
*ratio  active_1914
*sectour enc_1914 ratio  active_1914 cm_1914 incumbent
lab define support 0 "Suffrage Support" 1 "" 2 ""



sort clerical
local idir "~/Dropbox/Book/ms/images/France"	
foreach var in  ratio  enc_1914  active_1914  { 
		local v=`v'+1
		sum `var', detail
		_pctile `var', p(33(33)100)
		*gen competition bins
		
		gen comp_LMH=.
		replace comp_LMH=0 if `var'<=`r(r1)'
		replace comp_LMH=1 if `var'>`r(r1)' & `var'<=`r(r2)'
		replace comp_LMH=2 if `var'>`r(r2)' & `var'<=`r(r3)'
		
		
	forval n=0/2 {
		preserve
		keep if comp_LMH==`n'
		local compclass: label comp_LMH `n'
		egen bins = cut(clerical_peril), at(0(10)100)

		egen bin_it_up = mean(vote_1919), by(LCR  bins )
		
		if `n'==0  local aname="Suffrage Support"
		if `n'>=1  local aname=""
			egen nobs_`n'=count(bins) if comp_LMH ==`n', by(bins)
			local f`n': label comp_LMH `n'
			
			
			
			# delimit  ;
			twoway 	
				
				(lfit bin_it_up bins if LCR==1,  lwidth(vthick) )
				(lowess vote_1919 clerical_peril if LCR==1,  lwidth(vthick) )
				(scatter vote_1919 clerical_peril if LCR==1 ,  msize(small) msym(S)   mcolor(gs9) mlwidth(thick))
						
				 , legend( off)
				name(g`var'`n', replace) title(`compclass', size(vhuge)) ytitle("`aname'", size(huge)) xtitle("Clerical Peril, 1791", size(huge)) xlab(,labsize(large)) ylab(0(.20)1,labsize(large)) scheme(tufte) xscale(titlegap(*10))  ;
			
			# delimit cr
	
	graph export "~/Dropbox/Book/Teele_PUP/images_final/images_replication/fig22_`v'_`n'.eps", replace
	
	graph export "~/Dropbox/Book/Teele_PUP/images_final/images_replication/fig22_`v'_`n'.pdf", replace
	restore
	}
	

	

	

******
*Map -- Figure 19
******
*generated externally by separate program. Email me at teele.academic@gmail.com if you would like that code. 
